#pragma once

#include <iostream>

// 任务类
class Task
{
public:
    Task() = default;

    Task(int x, int y, char op)
        : _x(x)
        , _y(y)
        , _op(op)
    {}

    ~Task()
    {}

    // 处理任务
    void Execute(const std::string ThreadName)
    {
        int ret = 0;
        switch(_op)
        {
        case '+':
            ret = _x + _y;
            break;
        case '-':
            ret = _x - _y;
            break;
        case '*':
            ret = _x * _y;
            break;
        case '/':
            if(_y == 0)
            {
                std::cerr << "Error: Divided By Zero!" << std::endl;
                return;
            }
            else
            {
                ret = _x / _y;
            }
            break;
        case '%':
            if(_y == 0)
            {
                std::cerr << "Error: Modular Division By Zero!" << std::endl;
            }
            else
            {
                ret = _x % _y;
            }
            break;
        default:
            std::cerr << "Operation Error!" << std::endl;
            return;
        }
        std::cout << "[" << ThreadName << "]: " << _x << " " << _op << " " << _y << " = " << ret << std::endl;
    }

private:
    int _x;
    int _y;
    char _op;
};